package cn.magictodo.weblog.admin.controller;


import cn.magictodo.weblog.admin.model.vo.tag.AddTagReqVO;
import cn.magictodo.weblog.admin.model.vo.tag.DeleteTagReqVO;
import cn.magictodo.weblog.admin.model.vo.tag.FindTagPageListReqVO;
import cn.magictodo.weblog.admin.model.vo.tag.SearchTagReqVO;
import cn.magictodo.weblog.admin.service.AdminTagService;
import cn.magictodo.weblog.common.aspect.ApiOperationLog;
import cn.magictodo.weblog.common.utils.PageResponse;
import cn.magictodo.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章标签表 前端控制器
 * </p>
 *
 * @author liu
 * @since 2023-11-22
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 标签模块")
public class AdminTagController {

    @Autowired
    private AdminTagService tagService;

    @PostMapping("/tag/add")
    @ApiOperation(value = "添加标签")
    @ApiOperationLog(description = "添加标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response addTags(@RequestBody @Validated AddTagReqVO addTagReqVO) {
        return tagService.addTags(addTagReqVO);
    }

    @PostMapping("/tag/list")
    @ApiOperation(value = "标签分页数据获取")
    @ApiOperationLog(description = "标签分页数据获取")
    public PageResponse findTagPageList(@RequestBody @Validated FindTagPageListReqVO findTagPageListReqVO) {
        return tagService.findTagList(findTagPageListReqVO);
    }


    /**
     * @param deleteTagReqVO
     * @return
     */
    @PostMapping("/tag/delete")
    @ApiOperation(value = "删除标签")
    @ApiOperationLog(description = "删除标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteTag(@RequestBody @Validated DeleteTagReqVO deleteTagReqVO) {
        return tagService.deleteTag(deleteTagReqVO);
    }


    /**
     * 标签模糊查询数据获取
     * @param searchTagReqVO
     * @return
     */
    @PostMapping("/tag/search")
    @ApiOperation(value = "标签模糊查询数据获取")
    @ApiOperationLog(description = "标签模糊查询数据获取")
    public Response searchTagList(@RequestBody @Validated SearchTagReqVO searchTagReqVO) {
        return tagService.SearchTag(searchTagReqVO);
    }

    @PostMapping("/tag/select/list")
    @ApiOperation(value = "查询标签 Select 列表数据")
    @ApiOperationLog(description = "查询标签 Select 列表数据")
    public Response findTagSelectList() {
        return tagService.findTagSelectList();
    }


//
//    @PostMapping("/tag/select/list")
//    @ApiOperation(value = "标签 Select 下拉列表数据获取")
//    @ApiOperationLog(description = "标签 Select 下拉列表数据获取")
//    public Response findTagSelectList() {
//        return tagService.findCategorySelectList();
//    }
}

